package com.huanong.it.fooder.response;

public class ApiResponse<T> {
    private int code;
    private String message;
    private T data;

    public ApiResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 成功静态方法
    public static <T> ApiResponse<T> success(String message, T data) {
        return new ApiResponse<>(200, message, data);
    }

    // 失败静态方法
    public static <T> ApiResponse<T> fail(int code, String message) {
        return new ApiResponse<>(code, message, null);
    }

    @Override
    public String toString() {
        return "code: " + code + "\n" +
                "message: " + message + "\n" +
                "data: " + (data != null ? data.toString() : "null");
    }

    // Getter方法
    public int getCode() { return code; }
    public String getMessage() { return message; }
    public T getData() { return data; }
}
